package org.jeecg.common.api.vo;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;
import org.jeecg.common.util.StringUtils;

/**
 * @Description
 * @Author yangfeng
 * @Date 2021/2/9 11:00
 */
@Data
public class BaseQueryEntity {

    /**
     * 返回数据行
     */
    public  int  rows;
    /**
     * 当前页
     */
    public  int  pageNo;
    /**
     * 页大小
     */
    public  int  pageSize;

    /**
     * 排序字段名称
     */
    private  String column;
    /**
     *升序或者降序，asc or desc
     */
    private  String order;


    /**
     * 获得查询对象
     * @return
     */
    public QueryWrapper getQueryWrapper(){

        QueryWrapper queryWrapper = new QueryWrapper();
        if("asc".equalsIgnoreCase(order)){
            queryWrapper.orderByAsc(StringUtils.replaceUpperCaseToUnderLine(column));
        }else if("desc".equalsIgnoreCase(order)){
            queryWrapper.orderByDesc(StringUtils.replaceUpperCaseToUnderLine(column));
        }
        return queryWrapper;
    }

    /**
     * 获得分页对象
     * @return
     */
    public Page getPage(){
        if(pageNo == 0){
            pageNo = 1;
        }
        if(pageSize == 0){
            pageSize = 10;
        }
        return new Page(pageNo,pageSize);
    }

}
